
from selenium import webdriver
from selenium.webdriver.remote.webdriver import WebDriver
from demo.weworkSelenium.util.base_function import BaseFunction


class BasePage(BaseFunction):
    _base_url = ''
    _driver = None

    def __init__(self, driver: WebDriver = None, reuse=False):
        if driver is None:
            if reuse:
                options = webdriver.ChromeOptions()
                # 使用已经存在的chrome进程
                #  /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
                options.debugger_address = '127.0.0.1:9222'
                self._driver = webdriver.Chrome(options=options)
            else:
                self._driver = webdriver.Chrome()

            self._driver.implicitly_wait(3)
        else:
            self._driver = driver

        if self._base_url != '':
            self._driver.get(self._base_url)

    # def find(self, by, locator=''):
    #     # 判断传入的类型是否为元组类型
    #     if isinstance(by, tuple):
    #         return self._driver.find_element(*by)
    #     else:
    #         return self._driver.find_element(by, locator)
    #
    # def wait(self, by, locator=''):
    #     if isinstance(by, tuple):
    #         return WebDriverWait(self._driver, 10).until(
    #           expected_conditions.element_to_be_clickable(by)
    #         )
    #     else:
    #         return WebDriverWait(self._driver, 10).until(
    #           expected_conditions.element_to_be_clickable((by, locator))
    #         )
    #
    # def wait_hide(self, by, locator=''):
    #     if isinstance(by, tuple):
    #         return WebDriverWait(self._driver, 10).until_not(
    #           expected_conditions.element_to_be_clickable(by)
    #         )
    #     else:
    #         return WebDriverWait(self._driver, 10).until_not(
    #           expected_conditions.element_to_be_clickable((by, locator))
    #         )

    # def close(self):
    #     sleep(20)
    #     self._driver.quit()



